#include <bits/stdc++.h>

class Solution {
public:
    const bool Red = true, Blue = false;

    int n;

    std::vector<int> a;

    std::vector<bool> states;

    std::vector<int> last[2];

    long long res = 0;

    long long eval() {
        long long res = 0;
        for (int i = 1; i <= n; i++) {
            bool color = states[i];
            int lastSameColor = last[color][i];
            if (a[lastSameColor] == a[i]) {
                res += a[i];
            }
        }
        return res;
    }

    void dfs(int id) {
        if (id > n) {
            res = std::max(res, eval());
            return;
        }
        last[ states[id-1] ][id] = id - 1;
        last[ !states[id-1] ][id] = last[ !states[id-1] ][id-1];

        states[id] = Red;
        dfs(id + 1);
        states[id] = Blue;
        dfs(id + 1);
    }

    Solution(int n, std::vector<int> &a) {
        this->n = n;
        this->a = a;
        states.resize(n + 1);
        last[Red].resize(n + 1, 0);
        last[Blue].resize(n + 1, 0);
    }
};

int main() {
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    int t;
    std::cin >> t;
    for (int k = 0; k < t; k++) {
        int n;
        std::cin >> n;
        std::vector<int> a(n + 1);
        for (int i = 1; i <= n; i++) {
            std::cin >> a[i];
        }
        Solution sol(n, a);
        sol.dfs(1);
        std::cout << sol.res << std::endl;
    }
    return 0;
}